/*
 * One example for NOI CSP-J Lesson 6:
 * <https://courses.fmsoft.cn/plzs/noijunior-search-algorithms.html>
 *
 * Author: Vincent Wei
 *  - <https://github.com/VincentWei>
 *  - <https://gitee.com/vincentwei7>
 *
 * Copyright (C) 2025 FMSoft <https://www.fmsoft.cn>.
 * License: GPLv3
 */
#include <iostream>     // std::cout
#include <algorithm>    // std::find, std::find_if_not
#include <array>        // std::array

int main()
{
    std::array<int, 5> foo = {1, 2, 3, 4, 5};

    // 查找是否有 5
    std::array<int, 5>::iterator it;

    it = std::find(foo.begin(), foo.end(), 5);

    // 注意迭代子的用法
    if (it != foo.end())
        std::cout << "Value " << *it << " found in the array; index is " << it - foo.begin() << std::endl;
    else
        std::cout << "Element not found in foo\n";

    // 使用 Lambda 函数作为偶数的匹配条件
    it = std::find_if(foo.begin(), foo.end(), [](int i){ return i%2 == 0; });
    std::cout << "The first even value is " << *it << std::endl;

    // 使用 Lambda 函数作为奇数的匹配条件
    int nr_odd = std::count_if(foo.begin(), foo.end(), [](int i){ return i%2 != 0; });
    std::cout << "The number of odd values is " << nr_odd << std::endl;

    return 0;
}
